/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package managers;

import business.Talla;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.Table;

/**
 *
 * @author Desarrollo
 */
public class MngTallas extends Manager {

    public MngTallas() {

	}

	public boolean saveTalla(String talla, String t01, String t02, String t03, String t04, String t05, String t06, String t07,
							 String t08, String t09, String t10) {
		boolean res = false;

		try {
			cstm = stmt.getConnection().prepareCall("{call spc_saveTalla(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
			cstm.setString(1, talla);
			cstm.setString(2, t01);
			cstm.setString(3, t02);
			cstm.setString(4, t03);
			cstm.setString(5, t04);
			cstm.setString(6, t05);
			cstm.setString(7, t06);
			cstm.setString(8, t07);
			cstm.setString(9, t08);
			cstm.setString(10, t09);
			cstm.setString(11, t10);

			cstm.executeUpdate();
			res = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return res;
	}

    public Talla getTalla(String tal) {
        Talla talla = null;
        String sql = "SELECT * FROM tallas WHERE talla = '" + tal + "'";
        try {
            rst = stmt.executeQuery(sql);
            if (rst.next()) {
                talla = new Talla();
                talla.setTalla(tal);
                talla.setT01(rst.getString("t01"));
                talla.setT02(rst.getString("t02"));
                talla.setT03(rst.getString("t03"));
                talla.setT04(rst.getString("t04"));
                talla.setT05(rst.getString("t05"));
                talla.setT06(rst.getString("t06"));
                talla.setT07(rst.getString("t07"));
                talla.setT08(rst.getString("t08"));
                talla.setT09(rst.getString("t09"));
                talla.setT10(rst.getString("t10"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(MngTallas.class.getName()).log(Level.SEVERE, null, ex);
        }

        return talla;
    }

	public boolean deleteTalla(String talla) {
		String sql = "DELETE tallas.* FROM tallas WHERE talla = '" + talla + "'";

		return execUpdate(sql);
	}

    public static String getTable() {
        return getTable(false);
    }

    public static String getTable(boolean report) {
        String sql = "SELECT * FROM tallas";
        String fields = "talla,t01,t02,t03,t04,t05,t06,t07,t08,t09,t10";
        String editFunc = "editTalla";
        String editFields = "this";
        String delFunc = "delTalla";
        String delFields = "talla";

        return Table.getTable(sql, fields, editFunc, editFields, delFunc, delFields, report);
    }

    public String getPopup(String fields, String putFunc, String putFields) {
         String sql = "SELECT * FROM tallas";
         return Table.getPopup(sql, fields, putFunc, putFields);
    }
}
